package com.qr.controller;

import com.qr.constant.Constant;
import com.qr.dto.TemplateDTO;
import com.qr.entity.Template;
import com.qr.result.Result;
import com.qr.service.TemplateService;
import com.qr.vo.TempListVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
public class TemplateController {

    @Autowired
    private TemplateService templateService;

    @PostMapping("/addTemplate")
    public Result<String> addTemplate(@RequestBody TemplateDTO templateDTO) {
        log.info("添加模板：{}", templateDTO);
        templateService.addTemplate(templateDTO);
        return Result.success("添加模板成功");
    }

    @GetMapping("/getTemplate")
    public Result<List<Template>> getTemplate() {
        List<Template> template = templateService.getTemplate();
        return Result.success(template, Constant.SELECT_SUCCESS);
    }

    @GetMapping("/getTemplateById")
    public Result<List<TempListVO>> getTemplateById(Integer id) {
        log.info("查询模板：{}", id);
        List<TempListVO> voList = templateService.getTemplateById(id);
        return Result.success(voList, Constant.SELECT_SUCCESS);
    }

    @GetMapping("/deleteTemplate")
    public Result<String> deleteTemplate(Integer id) {
        log.info("删除模板：{}", id);
        templateService.deleteTemplate(id);
        return Result.success("删除模板成功");
    }
}
